package com.huidian.resource.client.enhance;

import com.huidian.cache.config.CacheManagerConfig;
import com.huidian.resource.client.StudentFeign;
import com.huidian.resource.client.dto.StudentDto;
import com.huidian.resource.client.enums.EmBaseCacheDef;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

/**
 * @author tjs
 */
public class StudentFeignEnhance implements StudentFeign {

    private StudentFeign studentFeign;
    public StudentFeignEnhance(StudentFeign studentFeign){
        this.studentFeign = studentFeign;
    }

    @Override
    public List<StudentDto> selectList(StudentDto studentDto) {
        return studentFeign.selectList(studentDto);
    }

    @Override
    @Cacheable(value = EmBaseCacheDef.STUDENT_ID_CACHE, key = "'stdId:'.concat(#stdId)",cacheManager = EmBaseCacheDef.STUDENT_CACHE_MANAGER,condition = "#stdId != null ")
    public StudentDto selectById(Long stdId) {
        return studentFeign.selectById(stdId);
    }

    @Cacheable(value = EmBaseCacheDef.STUDENT_INDEX_CACHE, key = "'schoolId:'.concat(#schoolId)",cacheManager = EmBaseCacheDef.STUDENT_CACHE_MANAGER,condition = "#schoolId != null ")
    public List<StudentDto> selectBySchoolId(Long schoolId) {
        StudentDto studentDto = new StudentDto();
        studentDto.setSchoolId(schoolId);
        return studentFeign.selectList(studentDto);
    }

    @Cacheable(value = EmBaseCacheDef.STUDENT_INDEX_CACHE, key = "'countyId:'.concat(#countyId)",cacheManager = EmBaseCacheDef.STUDENT_CACHE_MANAGER,condition = "#countyId != null ")
    public List<StudentDto> selectByCountyId(Long countyId) {
        StudentDto studentDto = new StudentDto();
        studentDto.setCountyId(countyId);
        return studentFeign.selectList(studentDto);
    }

    @Cacheable(value = EmBaseCacheDef.STUDENT_PAGE_CACHE, keyGenerator = CacheManagerConfig.KEY_GENERATOR,cacheManager = EmBaseCacheDef.STUDENT_CACHE_MANAGER,unless = "#result.size() > 100 ")
    public List<StudentDto> selectPageList(StudentDto studentDto) {
        return studentFeign.selectList(studentDto);
    }
}
